﻿using GrapeCity.Forguncy.CellTypes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Vant.WpfControls.DrawingObject
{
    /// <summary>
    /// SliderDrawingObject.xaml 的交互逻辑
    /// </summary>
    public partial class SliderDrawingObject : UserControl
    {
        public SliderDrawingObject(Vant.CellTypes.Slider slider, IDrawingHelper drawingHelper)
        {
            var viewModel = new SliderDrawingObjectViewModel();

            viewModel.BarCornerRadius = new CornerRadius(slider.barHeight / 2);
            viewModel.BarHeight = slider.barHeight;
            viewModel.ButtonCornerRadius = new CornerRadius(slider.buttonSize / 2);
            viewModel.ButtonSize = slider.buttonSize;
            viewModel.ActiveColor = drawingHelper.GetBrush(slider.activeColor);
            viewModel.InactiveColor = drawingHelper.GetBrush(slider.inactiveColor);
            if (!slider.vertical)
            {
                viewModel.ButtonMargin = new Thickness(-slider.buttonSize / 2, 0, 0, 0);
                viewModel.HVisibility = Visibility.Visible;
                viewModel.Margin = new Thickness(slider.buttonSize / 2, 0, slider.buttonSize / 2, 0);
            }
            else
            {
                viewModel.ButtonMargin = new Thickness(0, -slider.buttonSize / 2, 0, 0);
                viewModel.VVisibility = Visibility.Visible;
                viewModel.Margin = new Thickness(0, slider.buttonSize / 2, 0, slider.buttonSize / 2);
            }
            if (slider.range) 
            {
                if (slider.reverse)
                {
                    viewModel.ThridButtonVisiblity = Visibility.Visible;
                }
                else
                {
                    viewModel.SecondButtonVisiblity = Visibility.Visible;
                }
            }
            if (slider.IsDisabled)
            {
                viewModel.BarOpacity = 0.5;
            }
            if (slider.reverse)
            {
                viewModel.BarGridIndex = 1;
            }
            this.DataContext = viewModel;
            InitializeComponent();
        }
    }

    public class SliderDrawingObjectViewModel
    {
        public double BarHeight { get; set; }
        public Brush InactiveColor { get; set; }
        public CornerRadius BarCornerRadius { get; set; }
        public Brush ActiveColor { get; set; }
        public double ButtonSize { get; set; }
        public CornerRadius ButtonCornerRadius { get; set; }
        public Thickness ButtonMargin { get; set; }
        public Thickness Margin { get; set; }

        public Visibility HVisibility { get; set; } = Visibility.Collapsed;
        public Visibility VVisibility { get; set; } = Visibility.Collapsed;
        public Visibility SecondButtonVisiblity { get; set; } = Visibility.Collapsed;
        public Visibility ThridButtonVisiblity { get; set; } = Visibility.Collapsed;
        public double BarOpacity { get; set; } = 1;
        public double BarGridIndex { get; set; } = 0;
        
    }
}
